﻿using Hidistro.Core;
using Hidistro.Entities.Comments;
using Hidistro.Entities.Commodities;
using Hidistro.Membership.Context;
using Hidistro.SaleSystem.Catalog;
using Hidistro.SaleSystem.Comments;
using Hidistro.UI.SaleSystem.Tags;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using wnxd.Web;
using Hidistro.UI.Common.Controls;

namespace Hidistro.UI.AccountCenter.CodeBehind
{
    public class UserSuggestion : MemberTemplatedWebControl
    {
        protected override void AttachChildControls()
        {
            PageTitle.AddSiteNameTitle("意见建议");
        }
        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "User/Skin-UserSuggestion.html";
            }
            base.OnInit(e);
        }
        protected void Send()
        {
            Web wnxd_web = Web.FindFirst();
            string QQ = this.Page.Request.Form["QQ"], Phone = this.Page.Request.Form["Phone"], Content = this.Page.Request.Form["Content"];
            QQ = QQ == null ? null : QQ.Trim();
            Phone = Phone == null ? null : Phone.Trim();
            Content = Content == null ? null : Content.Trim();
            if (string.IsNullOrEmpty(QQ) && string.IsNullOrEmpty(Phone))
            {
                wnxd_web.AddScript("alert('QQ或手机号码至少填写一个');");
                return;
            }
            if (string.IsNullOrEmpty(Content) || Content.Length > 300)
            {
                wnxd_web.AddScript("alert('内容不能为空，长度限制在1-300个字符内');");
                return;
            }
            MessageBoxInfo messageBoxInfo = new MessageBoxInfo
            {
                Sernder = HiContext.Current.User.Username,
                Accepter = "admin",
                Title = "建议意见",
                Content = Globals.HtmlEncode("QQ: " + QQ + "\r\n手机: " + Phone + "\r\n\r\n" + Content)
            };
            if (CommentBrowser.SendMessage(messageBoxInfo))
            {
                wnxd_web.AddScript("alert('发送信息成功');");
            }
            else
            {
                wnxd_web.AddScript("alert('发送信息失败');");
            }
        }
    }
}
